/*
 * @(#)BaseAction.java
 *
 * Copyright 2012 by ShenY BIS, All rights reserved.
 */

package com.bis.framework.base.action;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.bis.common.service.CommonService;
import com.bis.framework.exception.entity.ExecuteResult;
import com.bis.framework.util.common.Page;
import com.bis.framework.util.common.PageData;
import com.opensymphony.xwork2.ActionSupport;

/**
 * BaseAction
 * 
 * @author BIS 2012-12-24
 */
public abstract class BaseAction extends ActionSupport implements SessionAware
{
    /**
     * Version Id
     */
    private static final long     serialVersionUID = 1L;
    /**
     * Logger
     */
    protected Logger              logger           = Logger.getLogger(getClass());
    /**
     * Common Service
     */
    protected CommonService       commonService    = null;
    /**
     * Content Type
     */
    protected static final String CONTENT_TYPE     = "text/html;charset=UTF-8";
    /**
     * Page Information
     */
    protected Page                objPage          = null;
    /**
     * Result Entity
     */
    protected ExecuteResult       executeResult    = new ExecuteResult();
    /**
     * Current Session Information
     */
    private Map                   session          = null;
    /**
     * Current Page Information
     */
    private int                   page             = 1;
    /**
     * Current Page Data
     */
    protected PageData            pageData         = null;

    /**
     * @return the logger
     */
    public Logger getLogger()
    {
        return logger;
    }

    /**
     * @param logger the logger to set
     */
    public void setLogger(Logger logger)
    {
        this.logger = logger;
    }

    /**
     * @return the commonService
     */
    public CommonService getCommonService()
    {
        return commonService;
    }

    /**
     * @param commonService the commonService to set
     */
    public void setCommonService(CommonService commonService)
    {
        this.commonService = commonService;
    }

    /**
     * @return the objPage
     */
    public Page getObjPage()
    {
        return objPage;
    }

    /**
     * @param objPage the objPage to set
     */
    public void setObjPage(Page objPage)
    {
        this.objPage = objPage;
    }

    /**
     * @return the executeResult
     */
    public ExecuteResult getExecuteResult()
    {
        return executeResult;
    }

    /**
     * @param executeResult the executeResult to set
     */
    public void setExecuteResult(ExecuteResult executeResult)
    {
        this.executeResult = executeResult;
    }

    /**
     * @return the session
     */
    public Map getSession()
    {
        return session;
    }

    /**
     * @param session the session to set
     */
    public void setSession(Map session)
    {
        this.session = session;
    }

    /**
     * @return the page
     */
    public int getPage()
    {
        try
        {
            if (getClass().toString().equals(ServletActionContext.getRequest().getSession().getAttribute("curClass")))
            {

                return Integer.parseInt((String) ServletActionContext.getRequest().getSession().getAttribute("curPage"));
            }
        }
        catch (Exception ex)
        {
            getLogger().error("Get Page....", ex);
        }
        return page;
    }

    /**
     * @param page the page to set
     */
    public void setPage(int page)
    {
        this.page = page;
        ServletActionContext.getRequest().getSession().setAttribute("curClass", getClass().toString());
        ServletActionContext.getRequest().getSession().setAttribute("curPage", "" + page);
    }

    /**
     * @return the pageData
     */
    public PageData getPageData()
    {
        return pageData;
    }

    /**
     * @param pageData the pageData to set
     */
    public void setPageData(PageData pageData)
    {
        this.pageData = pageData;
    }

    /**
     * @return the contentType
     */
    public static String getContentType()
    {
        return CONTENT_TYPE;
    }
}
